<extend name="layout/main" />

<block name="HEADER">

</block>

<block name="CONTENT">
    <div class="wrapper">
        <div class="panel-heading">
            <control:search id="searchs" />
        </div>
        <div class="content" >
            <div  class="fl"  style="width: calc(50% - 5px);height: 100%;margin-right: 10px;">
                <control:grid  id="grid" padding="0"  height="100%" />
            </div>
            <div  class="fl"  style="width: calc(50% - 5px);height: 100%;">
                <control:grid  id="seedGrid" padding="0"  height="100%"  />
            </div>
        </div>
    </div>
</block>

<block name="FOOTER">
    <script type="text/javascript">
    	var page=(function(ns){
    
		    //页面初始化
		    ns.init=function(){
		        grid.load([{"field":"nav_pid","opera":"=","value":"0"}]);
		    }
		    
		    //查询
		    ns.query=function(filter){
		        filter.push({"field":"nav_pid","opera":"=","value":"0"});
		        grid.load(filter);
		    }
		    
		    //加载子页面
		    ns.loadSeedGrid=function(){
		        var selectedRow=grid.getSelectedRows()[0];
		        if(selectedRow){
		            seedGrid.load([{"field":"nav_pid","opera":"=","value":selectedRow.nav_id}]);
		        }
		    }
		    
		    //备份
		    ns.upload=function(){
		        var rows=grid.getRows();
		        if(!rows[0]){
		           $.toast(0,"数据异常，不能进行备份！");
		           return;
		        };
		        $.confirm("确定覆盖上次的备份？", function(){
		            $.ajaxs("/admin/soft/nav/backups").then(function(res){
		                $.toast(1,"备份成功！");
		            });
		        });
		    }
		    
		    //还原
		    ns.reduction=function(){
		        $.ajaxs("/admin/soft/nav/getLastBackupsDate").then(function(res){
		            $.confirm("上次的备份时间是："+res.data+" </br>确定还原？", function(){
		                $.ajaxs("/admin/soft/nav/reduction").then(function(res){
		                    $.toast(1,"还原成功！");
		                    grid.load();
		                    seedGrid.load();
		                });
		            });
		        });
		    }
		    
		    //导出
		    ns.exports=function(){
		    	$.exports("/admin/soft/nav/exportExcel");
		    }
		    
		    //导入
		    ns.imports=function(){
		    	$.openImportHandle('/admin/soft/nav/importHandle',function(resp){
		    		$.toast(1,"导入成功！");
		            grid.load();
		            seedGrid.load();
		    	});
		    }
		   
		    
		    //新增
		    ns.add=function(){
		        var filter={
		            url:"system/pageMng/edit",
		            oid:"",
		            mode:1
		        }
		        $.openWin(filter, "新增父页面",['750px', '500px']);
		    }
		    
		    //编辑
		    ns.edit=function(){
		        var selectedRow=grid.getSelectedRows()[0];
		        var filter={
		            url:"system/pageMng/edit",
		            oid:selectedRow.nav_id,
		            mode:2
		        }
		        $.openWin(filter, "编辑父页面",['750px', '500px']); 
		    }
		    
		    //删除
		    ns.del=function(){
		        grid.deleteSelectRow(function(){
		           seedGrid.load();  
		        });
		    }
		    
		    //新增子页面
		    ns.addSeedGrid=function(){
		        var selectedRow=grid.getSelectedRows()[0];
		        if(!selectedRow){
		            $.toast(0,"请先选择父页面数据！");
		            return;
		        }
		        var filter={
		            url:"system/pageMng/editSeed",
		            oid:"",
		            mode:1,
		            nav_pid:selectedRow.nav_id,
		            p_nav_name:selectedRow.nav_name
		        }
		        $.openWin(filter, "新增子页面",['750px', '500px']); 
		    }
		    
		    //编辑子页面
		    ns.editSeedGrid=function(){
		        var selectedRow=seedGrid.getSelectedRows()[0];
		        var filter={
		            url:"system/pageMng/editSeed",
		            oid:selectedRow.nav_id,
		            mode:2,
		        }
		        $.openWin(filter, "编辑子页面",['750px', '500px']); 
		    }
		    
		    //删除子页面
		    ns.delSeedGrid=function(){
		        seedGrid.deleteSelectRow();
		    }
		    
		    //启用与禁用
		    //mode=1 等于禁用
		    ns.enableAndStand=function(mode){
		    	var grids=grid;
		        if(mode>1){
		        	grids = seedGrid;
		        	mode =  mode == 2 ? 0 : 1;
		        }
		        var selectedRow=grids.getSelectedRows();
		        if(!selectedRow[0]){
		            $.toast(0,"请先选择数据！");
		            return;
		        }
		        var param = { 
		        	data:$.map(selectedRow, function(h) {
		        		return {
						 	nav_id: h.nav_id,
						 	nav_status: mode
						}
		        	})
		        }
		        $.ajaxs("/admin/soft/nav/setEnable",param,function(res){
		            grids.load()
		        });
		    }
		    
		    //移动
		    ns.move=function(mode){
		    	var grids=grid;
		        if(mode>1){
		        	grids = seedGrid;
		        	mode =  mode == 2 ? 0 : 1;
		        }
		        var rows = grids.getRows();
		        var selectedRow=grids.getSelectedRows();
		        if(!selectedRow[0]){
		            $.toast(0,"请先选择数据！");
		            return;
		        }
		        if(selectedRow.length>1){
		            $.toast(0,"只能选择一条数据！");
		            return;
		        }
		        var coverId=-1;
		      	rows.forEach(function(h,index){
		      		if(selectedRow[0].nav_id==h.nav_id){
		      			if(mode==0){
		      				if(rows[index-1]){
		      					coverId = rows[index-1].nav_id;
		      				}
		      			}else{
		      				if(rows[index+1]){
		      					coverId = rows[index+1].nav_id;
		      				}
		      			}
		      		}
		      	});
		        var param={ moveId:selectedRow[0].nav_id, coverId:coverId}
		        $.ajaxs("/admin/soft/nav/sortMove",param,function(res){
		        	grids.load()
		        });
		    }
		    
		    return ns;
		}({}));
		
		$(function(){  page.init();  });
    </script>
</block>



